﻿using System;

namespace Trentacular.SharePoint.Features.Web.UI.WebParts
{
    /// <summary>
    /// Use to associate an EditorPart to a WebEditableWebPart.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
    public class EditorPartAttribute : Attribute
    {
        /// <summary>
        /// Gets the EditorPart ID.
        /// </summary>
        /// <value>The ID.</value>
        public string ID { get; private set; }

        /// <summary>
        /// Gets the EditorPart title.
        /// </summary>
        /// <value>The title.</value>
        public string Title { get; private set; }

        /// <summary>
        /// Gets the type of the EditorPart.
        /// </summary>
        /// <value>The type of the editor part.</value>
        public Type EditorPartType { get; private set; }

        /// <summary>
        /// Gets the user control virtual path to a control that implements
        /// the <see cref="IWebPartEditor<T>"/> interface.
        /// </summary>
        /// <value>The user control virtual path.</value>
        public string UserControlVirtualPath { get; private set; }

        private EditorPartAttribute(string id, string title)
        {
            this.ID = id;
            this.Title = title;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EditorPartAttribute"/> class.
        /// </summary>
        /// <param name="id">The id of the EidtorPart.</param>
        /// <param name="title">The title of the EditorPart.</param>
        /// <param name="editorPartType">The type of the EditorPart.</param>
        public EditorPartAttribute(string id, string title, Type editorPartType)
            : this(id, title)
        {
            this.EditorPartType = editorPartType;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EditorPartAttribute"/> class.
        /// </summary>
        /// <param name="id">The id of the EditorPart.</param>
        /// <param name="title">The title of the EditorPart.</param>
        /// <param name="userControlVirtualPath">The user control virtual path to a
        /// control that implements the <see cref="IWebPartEditor<T>"/>
        /// interface.</param>
        public EditorPartAttribute(string id, string title,
            string userControlVirtualPath)
            : this(id, title)
        {
            this.UserControlVirtualPath = userControlVirtualPath;
        }
    }
}
